package com.aop.demo.controller;

import com.aop.demo.aop.AopAnnotation;
import com.aop.demo.aop.AopAnnotation1;
import com.aop.demo.bean.User;
import com.aop.demo.service.UserService;
import com.aop.demo.service.UserValidator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author H
 * @date 2023/1/1
 */
@RestController
public class UserController {

    @Autowired
    private UserService userService;

    @AopAnnotation1("222")
    @AopAnnotation("111")
    @GetMapping("test")
    public String test() {
        User user = new User();
        user.setUsername("小明");
        user.setGender(1);
        // 为这个接口引入新的接口，来增强该接口的功能
        UserValidator userValidator = (UserValidator) userService;
        if (userValidator.validate(user)) {
            userService.print(user);
        }
        // userService.testAop1();
        System.out.println("------> 方法执行");
        return "success";
    }

    @AopAnnotation(value = "你好，世界", type = 26)
    @GetMapping("login/{username}")
    public String login1(@PathVariable String username) {
        String test = test1();
        return test;
    }

    protected String test1() {
        return "a";
    }
}
